﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AssetManager
{
    public partial class AssetDetails : Form
    {
        int assetID;

        public AssetDetails(Int32 AssetID)
        {
            AssetServiceRef.IAssetService sr = new AssetServiceRef.AssetServiceClient();
            InitializeComponent();
            this.WindowState = FormWindowState.Maximized;
            assetID = AssetID;
            FillAssetDetails();
            FillPurchaseDetails();
        }

        private void FillAssetDetails()
        {
            AssetServiceRef.IAssetService sr = new AssetServiceRef.AssetServiceClient();

            DataTable dt = sr.GetAssetDetails(assetID);
            foreach (DataRow r in dt.Rows)
            {
                txtName.Text = r["Name"].ToString();
                txtMetadata.Text = r["Metadata"].ToString();
                txtModel.Text = r["ModelNumber"].ToString();
                txtManufacturer.Text = r["Manufacturer"].ToString();
                txtMake.Text = r["Make"].ToString();
                txtSerialNum.Text = r["SerialNumber"].ToString();
                txtYear.Text = r["Year"].ToString();
                string comments = r["Comments"].ToString();
                rtfAssetComments.AppendText(comments);
            }
        }

        private void FillPurchaseDetails()
        {
            AssetServiceRef.IAssetService sr = new AssetServiceRef.AssetServiceClient();

            DataTable dt = sr.GetPurchaseDetails(assetID);
            foreach (DataRow r in dt.Rows)
            {
                txtPurchaseDate.Text = r["Date"].ToString();
                txtValue.Text = r["Value"].ToString();
                txtStore.Text = r["Store"].ToString();
                string comments = r["comments"].ToString();
                rtfPurchaseComments.AppendText(comments);
            }
        }

        private void FillScheduleDetails()
        {
            AssetServiceRef.IAssetService sr = new AssetServiceRef.AssetServiceClient();

            DataTable dt = sr.GetScheduleDetails(assetID);
            foreach (DataRow r in dt.Rows)
            {
                //txtSchedTitle.Text = ;
                string comments = r["comments"].ToString();
                rtfPurchaseComments.AppendText(comments);
            }
        }
        private void FillServiceDetails()
        {
            AssetServiceRef.IAssetService sr = new AssetServiceRef.AssetServiceClient();

            DataTable dt = sr.GetServiceDetails(assetID);
            foreach (DataRow r in dt.Rows)
            {

                string comments = r["comments"].ToString();
                rtfPurchaseComments.AppendText(comments);
            }
        }

        private void FillWarrantyDetails()
        {
            AssetServiceRef.IAssetService sr = new AssetServiceRef.AssetServiceClient();

            DataTable dt = sr.GetWarrantyDetails(assetID);
            foreach (DataRow r in dt.Rows)
            {

                string comments = r["comments"].ToString();
                rtfPurchaseComments.AppendText(comments);
            }
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            txtName.Enabled = true;
            txtMetadata.Enabled = true;
            txtModel.Enabled = true;
            txtManufacturer.Enabled = true;
            txtMake.Enabled = true;
            txtSerialNum.Enabled = true;
            txtYear.Enabled = true;
            rtfAssetComments.Enabled = true;
        }

        private void btnEditPurchase_Click(object sender, EventArgs e)
        {
            txtPurchaseDate.Enabled = true;
            txtValue.Enabled = true;
            txtStore.Enabled = true;
            rtfPurchaseComments.Enabled = true;
        }
    }
}
